package com.ykt.service;

import com.ykt.converter.ServiceConverter;
import com.ykt.model.Order;
import com.ykt.model.Service;
import com.ykt.vo.ServiceVo;

import java.util.List;

/**
 * @author long.hua
 * @version 1.0.0
 * @since 2016-04-17 21:28
 */
public class AfterSalesService {

    private Order orderDao = Order.dao;
    private Service serviceDao = Service.dao;

    public int save(Service service) {
        boolean flag = service.save();
        if (flag) {

            // 更新订单售后状态
            orderDao.set(Order.id, service.get(Service.order_id));
            orderDao.set(Order.service_status, Order.ServiceStatus.DELAY_SERVICE.name());
            orderDao.update();

            return service.getId();
        }

        return -1;
    }

    // 根据orderId查询服务
    public List<ServiceVo> findByOrderId(int orderId){
        List<Service> serviceList = serviceDao.findByOrderId(orderId);
        List<ServiceVo> serviceVos = ServiceConverter.convert(serviceList);
        return serviceVos;
    }

    public Service findLastService(int orderId){
        return serviceDao.findLastService(orderId);
    }
}
